package ThreadDemo;

/**
 * @author:周鹏
 * @date: 2020/11/10 16:20
 * @description:静态代理
 */
public class StaticProxy {
/*
1.代理对象和真实对象实现同一个接口
2.代理对象实现真实对象（增强真实对象）
3.真实对象专注自身业务
 */

    public static void main(String[] args) {
    //此处people类实现了buy接口就能被用作初始化对象
       new company(new peopele()).shoppingbuy();
    }
}
    interface buy {
        void shoppingbuy();
    }

    //真实对象
    class peopele implements buy {

        @Override
        public void shoppingbuy() {
            System.out.println("付了100元");
        }
    }

    //代理对象
    class company implements buy {
        //获取代理目标对象
        private buy target;

        //构造方法获取对象(传参)
        public company(buy target) {
            this.target = target;
        }

        private void first() {
            System.out.println("先下订单");
        }

        private void end() {
            System.out.println("领取货物");
        }

        @Override
        public void shoppingbuy() {
            first();
            target.shoppingbuy();
            end();


        }
    }

